/**
 * 获取一个随机颜色 #dd00ee
 */
function randomColor() {
	var color = "";
	var rgb = [];
	for (let i = 0; i < 3; i++) {
		color = Math.floor(Math.random() * 256).toString(16);
		color.length == 1 ? "0" + color : color;
		rgb.push(color);
	}
	return "#" + rgb.join("");

}


/**
 * dateStr 为空  则返回当前日期是周几
 * 获取一个指定日期是周几
 */
function getWeeekDay(dateStr) {
	var date = new Date();
	if (dateStr) {
		date = new Date(dateStr);
	}
	var day = date.getDay(); //返回一周的某一天数字。
	var weekArr = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	return weekArr[day];
}



/**
 * 计算 日期相差天数
 */
function datedifference(sDate1, sDate2) { //sDate1和sDate2是2006-12-18格式
	var dateSpan,
		tempDate,
		iDays;
	sDate1 = Date.parse(sDate1);
	sDate2 = Date.parse(sDate2);
	dateSpan = sDate2 - sDate1;
	dateSpan = Math.abs(dateSpan);
	iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
	return iDays
}


//js 获取当前时间
function fnDate(selector) {
	var oDiv = "";
	var date = new Date();
	var year = date.getFullYear(); //当前年份
	var month = date.getMonth(); //当前月份
	var data = date.getDate(); //天
	var hours = date.getHours(); //小时
	var minute = date.getMinutes(); //分
	var second = date.getSeconds(); //秒
	var time = year + "-" + fnW((month + 1)) + "-" + fnW(data) + " " + fnW(hours) + ":" + fnW(minute) + ":" + fnW(second);
	
	if(selector){
		oDiv=document.getElementById(selector);
		oDiv.innerHTML=time;
	}else{
	    return time;	
	}
	
}
//补位 当某个字段不是两位数时补0
function fnW(str) {
	var num;
	str < 10 ?num = "0" + str : num = str ; 
	return num;
}


/**
 * [获取URL中的参数名及参数值的集合]
 * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
 * @param {[string]} urlStr [当该参数不为空的时候，则解析该url中的参数集合]
 * @return {[string]}       [参数集合]
 */
function GetRequest(urlStr) {
    if (typeof urlStr == "undefined") {
        var url = decodeURI(location.search); //获取url中"?"符后的字符串
    } else {
        var url = "?" + urlStr.split("?")[1];
    }
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

/**
 * [通过参数名获取url中的参数值]
 * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
 * @param  {[string]} queryName [参数名]
 * @return {[string]}           [参数值]
 */
function GetQueryValue(queryName) {
    var query = decodeURI(window.location.search.substring(1));
	console.log(window.location.search)
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == queryName) { return pair[1]; }
    }
    return null;
}


 /**
     * 去除空格
     * @param {str}
     * @param {type}
     *    type: 1-所有空格 2-前后空格 3-前空格 4-后空格
     * @return {String}
     */
function trim (str, type) {
      type = type || 1
      switch (type) {
        case 1:
          return str.replace(/\s+/g, "");
        case 2:
          return str.replace(/(^\s*)|(\s*$)/g, "");
        case 3:
          return str.replace(/(^\s*)/g, "");
        case 4:
          return str.replace(/(\s*$)/g, "");
        default:
          return str;
      }
 }
 
 
